import openpyxl

# 打开Excel文件
wb = openpyxl.load_workbook('data/ExcelData/sort.xlsx')
# 选择工作表
sheet = wb['Sheet1']
#特定字符
character1 = " \" "


# 跟踪行号的计数器
row_counter = 0

# 保存修改后的内容
modified_content = ""

# 遍历需要修改的单元格
for row in sheet.iter_rows(min_row=1, min_col=1, max_row=sheet.max_row, max_col=2):
    row_counter += 1
    if row_counter % 5 == 1:
        modified_content += character1 +str(row[1].value) + character1 +":" + "{"
    elif row_counter % 5 == 0:
        modified_content += character1 + str(row[0].value) + character1 + ":"
        modified_content += str(row[1].value) + "," + "}" + ","
    else:
        modified_content += character1 + str(row[0].value) + character1 + ":"
        modified_content += str(row[1].value) + ","

    modified_content += "\n"

# 保存为txt文件
with open('sort.txt', 'w') as file:
    file.write(modified_content)